function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function () {

    $(".focused").click(function () {
        //  取消关注当前新闻作者
        var user_id = $(this).attr('data-userid')
        var params = {
            "user_id":user_id,
            "action":"unfollow"
        }
        $.ajax({
            url:"/news/user_followed",
            type:'post',
            data:JSON.stringify(params),
            contentType:"application/json",
            headers:{
                "X-CSRFToken":getCookie('csrf_token')
            },
            success:function(resp){
                if (resp.errno == 0){
                    // var count = parseInt($('.follows b').html())
                    // count--;
                    // $('.follows b').html(count+"")
                    // $('.focus').show()
                    // $('.focused').hide()
                    location.reload()
                }
                else if (resp.errno == 4104){
                    $('.login_form_con').show()
                }
                else{
                    alert(resp.errmsg)
                }
            }
        })
    })
})